package com.zhhs.galaxyott.httpVolley.parser;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.zhhs.galaxyott.beans.VipDataBean;
import com.zhhs.galaxyott.httpVolley.response.BaseResponse;
import com.zhhs.galaxyott.httpVolley.response.VipDataResponse;

/**
 * vip信息解析器
 * 
 * 
 */
public class VipDataParser extends BaseParser<VipDataResponse> {

    @Override
    public BaseResponse parse(String jsonString) {
        VipDataResponse mResponse = new VipDataResponse();
        try {
            JSONObject json = new JSONObject(jsonString);
            parseMsg(json, mResponse);

            if (mResponse.errCode == 0) {
                JSONArray result = json.getJSONArray("list");
                if (result != null && result.length() > 0) {
                    for (int i = 0; i < result.length(); i++) {
                        VipDataBean vdb = new VipDataBean();
                        JSONObject jsonr = result.getJSONObject(i);
                        if (jsonr.has("packageId")) {
                            vdb.setPackageId(jsonr.optInt("packageId"));
                        }
                        if (jsonr.has("packageName")) {
                            vdb.setPackageName(jsonr.optString("packageName"));
                        }
                        if (jsonr.has("packageCode")) {
                            vdb.setPackageCode(jsonr.optString("packageCode"));
                        }
                        if (jsonr.has("packagePrice")) {
                            vdb.setPackagePrice(jsonr.optDouble("packagePrice"));
                        }
                        if (jsonr.has("packageSort")) {
                            vdb.setPackageSort(jsonr.optInt("packageSort"));
                        }
                        mResponse.lvdb.add(vdb);
                    }
                }
            }

        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return mResponse;
    }

}
